import java.util.Random;
import java.util.Scanner;

/**
 * @User: vitobo
 * @Date: 2024-03-04
 * @Description: 逻辑控制学习
 */
public class logic {

    // 猜数字
    public static void main(String[] args) {
        Random random = new Random();
        Scanner sc = new Scanner(System.in);
        int toGuess = random.nextInt(100);
        System.out.println("toGuess: " + toGuess);
        while(true){
            System.out.println("请输入你猜的数字(1-100): ");
            int num = sc.nextInt();
            if(num < toGuess){
                System.out.println("猜小了");
            }else if(num > toGuess){
                System.out.println("猜大了");
            }else{
                System.out.println("猜对了");
                break;
            }

        }
        sc.close();
    }



    // do while 循环
    public static void main5(String[] args) {


        // 循环读入N个数字, 求平均值
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        int num = 0;
        while(sc.hasNextInt()){
            int tmp = sc.nextInt();
            sum += tmp;
            num++;
        }
        System.out.println("sum= " + sum);
        System.out.println("avg= " + sum/num);
        sc.close();



/*        // 从键盘输入
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的姓名: ");
        String name = sc.nextLine();

        System.out.println("请输入你的年龄: ");
        int age = sc.nextInt();

        System.out.println("请输入你的工资: ");
        float salary = sc.nextFloat();

        System.out.println("您的信息如下: ");
        System.out.println("姓名: " + name + "\n" + "年龄: " + age + "\n" + "工资: " + salary);
        sc.close();*/


/*        String str = "hahahaha";
        System.out.println(str);
        //System.out.print(str);
        int x = 100;
        System.out.printf("x=%x\n", x);*/

/*        int num = 1;
        do{
            System.out.println(num);
            num++;
        }while(num <= 10);*/

    }

    // for循环
    public static void main4(String[] args) {

        int sum = 0;
        for (int i = 1; i <= 5; i++) {
            int tmp = 1;
            for (int j = 1; j <= i; j++) {
                tmp *= j;
            }
            sum += tmp;
        }
        System.out.println("sum= " + sum);

        /*int ret = 1;
        for (int i = 1; i <= 5; i++) {
            ret *= i;
        }
        System.out.println(ret);*/

        /*int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        System.out.println("sum= " + sum);*/

        /*for (int i = 1; i <= 10; i++) {
            System.out.println(i);
        }*/
    }


    public static void main3(String[] args) {

        // 循环结构 while
        // break
        /*int num = 100;
        while(num <= 200){
            if(num % 3 == 0){
                System.out.println("3的倍数: " + num);
                break;
            }
            num++;
        }*/

        // continue
        int num = 100;
        while(num <= 200){
            if(num % 3 == 0){
                System.out.println("3的倍数: " + num);
                num++;
                continue;
            }
            num++;
        }



        /*// 计算1-5的阶乘和
        int num = 1;
        int sum = 0;
        while(num <= 5){
            int ret = 1;
            int i = 1;
            while(i <= num){
                ret *= i;
                i++;
            }
            sum += ret;
            num++;
        }
        System.out.println(sum);*/

        /*// 计算5的阶乘
        int i = 1;
        int ret = 1;
        while(i <= 5){
            ret *= i;
            i++;
        }
        System.out.println(ret);*/

        /*// 计算 1-100的和
        int i = 1;
        int sum = 0;
        while(i <= 100){
            sum += i;
            i++;
        }
        System.out.println(sum);*/

        /*// 打印1-10
        int i = 1;
        while(i <= 10){
            System.out.println(i);
            i++;
        }*/

    }


    public static void main2(String[] args) {
        // switch() 括号内表达式, 不能是long, float, double, boolean类型
        // 可以是 byte, char, short, int, String, enum枚举类型

        /*Scanner scanner = new Scanner(System.in);
        int day = scanner.nextInt();
        switch(day){
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            case 3:
                System.out.println("星期三");
                break;
            case 4:
                System.out.println("星期四");
                break;
            case 5:
                System.out.println("星期五");
                break;
            case 6:
                System.out.println("星期六");
                break;
            case 7:
                System.out.println("星期日");
                break;
            default:
                System.out.println( );
                break;
        }*/

    }


    public static void main1(String[] args) {
        // 分支结构 if-else

        // 判断一个年份是否为闰年
        Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();
        if(((year % 4 == 0) && (year % 100 != 0) )|| (year % 400 ==0)){
            System.out.println(" 闰年");
        }else{
            System.out.println(" 不是闰年");
        }


/*        // 正数, 负数, 0
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        if(num > 0){
            System.out.println("正数");
        }else if(num < 0){
            System.out.println("负数");
        }else {
            System.out.println("0");
        }*/

/*        // 判断一个数字是奇偶数
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        if(num % 2 != 0){
            System.out.println(num + "是奇数");
        }else{
            System.out.println(num + "是偶数");
        }*/

/*       Scanner scanner = new Scanner(System.in);
        int sorce = scanner.nextInt();
        if(sorce >= 90){
            System.out.println("优秀");
        }else if(sorce >= 80 && sorce <90){
            System.out.println("良好");
        }else if(sorce >= 70 && sorce <80){
            System.out.println("中等");
        }
        else if(sorce >= 60 && sorce <70){
            System.out.println("及格");
        }else if(sorce >= 0 && sorce <60){
            System.out.println("不及格");
        }else {
            System.out.println("输入错误");
        }*/


        /*// 顺序结构
        System.out.println("hello");
        System.out.println("word");*/
    }
}
